<?php
/**
 * 测试redis并发
 */
require_once 'db.php';
$redis = new Redis();
$redis->connect('120.79.218.85', 6379);
$db = new myPDO();
$redis->watch("num");
$num = $redis->get('num');
$up="";
$res = $db->getDate('select * from product');
if ($num==0){
    echo '秒杀结束';exit;

}else{
    $redis->multi();/*开启事物*/
    $redis->set('num',$res['stock']);
    $ress = $redis->exec();
    if ($ress){
        sleep(1);
        $sql = "update product set stock=stock-1 where id=1";
        $up = $db->update($sql);
    }
}
print_r($up);exit;